﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Xml.Linq;
using Smarly.Ebook.BussinesLayer;
using Smarly.Ebook.Model;

namespace Smarly.Ebook
{
	public static class IndesignPocess
	{
		public static string Process(string str, EBookTree prev, EBookTree next)
		{
			XDocument original = XDocument.Parse(string.Format("<div>{0}</div>", str), LoadOptions.PreserveWhitespace);

			XDocument result = XDocument.Parse(string.Format("<div></div>", str), LoadOptions.PreserveWhitespace);

			result.Root.Add(new XAttribute(XNamespace.Xmlns + "aid", Smarly.Ebook.BussinesLayer.Element.aid.NamespaceName));
			result.Root.Add(new XAttribute(XNamespace.Xmlns + "aid5", Smarly.Ebook.BussinesLayer.Element.aid5.NamespaceName));

			foreach (var child in original.Elements())
			{
				Element.Parse(child, result.Root);
			}

			var reader = result.Root.CreateReader();
			reader.MoveToContent();
			return reader.ReadInnerXml();
		}


	}
}